package com.ruoyi.project.secs;

import com.glorysoft.secsgem.core.HSMSParameters;
import com.glorysoft.secsgem.core.eSECS_FORMAT;
import com.glorysoft.secsgem.secsmsg.*;


/**
 * 货架管理
 */
public class TestController {

    public static SECSPort port;

    public static void main(String[] args) throws Exception {
        /**
         * H->E 主机发送设备
         * E->H 设备发送主机
         * H<->E 双向
         */


        port = new SECSPort("test");
        //port.setPortType(eSECS_PORT_TYPE.HSMS);
        HSMSParameters hsmsParameters = port.getHsmsParameters();
        hsmsParameters.setRemoteIP("127.0.0.1");
        hsmsParameters.setRemotePort(5000);
        hsmsParameters.setIsHost(true);
        port.addSECSEventHandler(new MyMessageDispatcher());
        //port.getLibrary().Load("C:\\Users\\dxm\\Desktop\\xxx\\SECSwellLibrary.xml");


        port.OpenPort();

        //SECSTransaction t = port.getLibrary().FindTransaction("S18F71");
        //port.Send(t);

        //SECSLibrary library = port.getLibrary();








       //port.ClosePort();
    }

    public static void send(){
        MessageAbstractSECSLibrary messageAbstractSECSLibrary = new MessageAbstractSECSLibrary();
        messageAbstractSECSLibrary.AddMessage(getMessage());
        SECSTransaction s1F3 = messageAbstractSECSLibrary.FindTransaction("s1F3");


        //port.setLibrary(library);
        //SECSTransaction s18F75 = library.FindTransaction("S18F75");
        port.Send(s1F3);
    }

    public static SECSMessage  getMessage(){
        SECSMessage msg = new SECSMessage();
        msg.setStream(1);
        msg.setFunction(3);
        msg.setWBit(true); //是否需要回复

        msg.setRoot(new SECSItem(eSECS_FORMAT.LIST));
//        SECSItem A1 = new SECSItem(eSECS_FORMAT.ASCII);
//        A1.setValue("ATF001");
//        A1.setValue("AIMFAb");
//        msg.getRoot().Add(A1);

//        SECSItem A2 = new SECSItem(eSECS_FORMAT.ASCII);
//        A2.setValue("VO1RO1");
//        msg.getRoot().Add(A2);

        SECSItem I2 = new SECSItem(eSECS_FORMAT.I2);
        I2.setValue((short)0);
        msg.getRoot().Add(I2);

        /*SECSItem U1 = new SECSItem(eSECS_FORMAT.U1);
        byte b = 6;
        U1.setValue(b);
        msg.getRoot().Add(U1);

        SECSItem A3 = new SECSItem(eSECS_FORMAT.ASCII);
        A3.setValue("REMOVE");
        msg.getRoot().Add(A3);*/
        return msg;
    }




}
